import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2023-04-19
 * Time: 14:21
 */

class MyArray<T> {
    //public T[] objects = new T[10];//ERROR 1、不能实例化泛型类型的数组
    public T[] objects = (T[])new Object[10];
    //public Object[] objects = new Object[10];
    public void set(int pos,T val) {
        objects[pos] = val;
    }

    public T get(int pos) {
        return objects[pos];
    }

    public T[] getArray() {
        return objects;
    }
}
class Alg<T extends Comparable<T>> {
    public T findMax(T[] array) {
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if (max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}

class Alg2 {
    public static <T extends Comparable<T>>T findMax(T[] array) {
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if (max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
class Alg3 {
    public static <T> void print1(ArrayList<T> list) {
        for (T x: list) {
            System.out.println(x);
        }
    }
    public static void print2(ArrayList<?> list) {
        for (Object x: list) {
            System.out.println(x);
        }
    }
}
public class TestDemo {
    public static void main(String[] args) {

    }
    public static void main3(String[] args) {
        Integer[] array = {1,2,3,4,7,5,6,9,100,97,123};
        System.out.println(Alg2.<Integer>findMax(array));
        String[] array1 = {"abc","xxhljq","hello"};
        System.out.println(Alg2.<String>findMax(array1));
    }
    public static void main2(String[] args) {
        Alg<Integer> alg = new Alg<>();
        Integer[] array = {1,2,3,4,7,5,6,9,100,97,123};
        System.out.println(alg.findMax(array));
        Alg<String> alg1 = new Alg<>();
        String[] array1 = {"abc","xxhljq","hello"};
        System.out.println(alg1.findMax(array1));
    }
    public static void main1(String[] args) {
        MyArray<String> myArray = new MyArray<String>();
        Object[] ret = myArray.getArray();//编译器认为 此时 并不是很安全
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        Object[] ret2 = arrayList.toArray();
    }
}
